<template>
	<div class="login container">
		<Header>
			<span>
				找回密码
			</span>
		</Header>
		<section>
			<div class='login-tel'>
				<input type="password" v-model="userPwd" placeholder="请输入新密码" pattern="[0-9]*">
			</div>
			
			<div class='login-btn' @click='submitBtn'>确认重置密码</div>
			<!-- <div class='tab'>
				<span @click='goUserLogin'>密码登录</span>
				<span @click='goRegister'>快速注册</span>
			</div> -->
		</section>
		<Tabbar></Tabbar>
	</div>
</template>

<script>
import Tabbar from '@/components/common/Tabbar.vue'
import Header from '@/views/login/Header.vue'
import { Toast } from 'mint-ui';
import http from '@/common/api/request.js'
export default{
	data(){
		return {
			userPwd:'',//用户输入的密码
			//验证规则
			rules:{
				//密码验证
				userPwd:{
					rule:/^\w{6,12}$/,
					msg:'密码不能为空，并且要求6,12位'
				}
			}
		}
	},
	components:{
		Header,
		Tabbar
	},
	
	methods:{
		//验证信息提示
		validate( key ){
			let bool = true;
			if( !this.rules[key].rule.test( this[key])  ){
				//提示信息
				Toast(this.rules[key].msg);
				bool = false;
				return false;
			}
			return bool;
		},
		//点击下一步
		submitBtn(){
			console.log("确认");
			console.log(this.userPwd);
			//密码验空
			if( !this.validate('userPwd') ) return;
				
			//验证不为空
			//发送请求
			http.$axios({
				url:'/api/recovery',
				method:'POST',
				data:{
					phone:this.$route.query.phone,
					pwd:this.userPwd
				}
			}).then(res=>{
				if(res.success){
					Toast('密码重置成功');
					this.$router.push({
						path:'/userLogin'
					})
				}
			})
				
			
			
			
		},
		
	}
}
</script>

<style scoped lang="scss">
	section{
		display: flex;
		flex-direction: column;
		align-items: center;
		background-color:#f5f5f5;
		div{
			margin:15px 0;
			width: 335px;
			height: 44px;
		}
		input{
			box-sizing: border-box;
			padding:0 10px;
			line-height: 44px;
			background-color: #FFFFFF;
			border:1px solid #ccc;
			border-radius: 6px;
		}
		.login-tel{
			margin-top:30px;
			input{
				width: 335px;
			}
		}
		.login-code{
			display: flex;
			input{
				flex:1;
			}
			button{
				margin-left: 10px;
				padding:0 20px;
				line-height: 44px;
				color:#fff;
				background-color: #b0352f;
				border:0;
				border-radius: 6px;
			}
		}
		.login-btn{
			line-height: 44px;
			font-size: 25px;
			color:#fff;
			text-align: center;
			background-color: #b0352f;
			border-radius: 6px;
		}
		.tab{
			display: flex;
			justify-content: space-between;
			font-size: 14px;
		}
	}
</style>
